package net.ib.mtalk.util;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.content.Context;

public class HttpUtil {
	// HTTP URL로부터 이미지 파일을 다운로드받아 로컬에 저장한다. 
	public static boolean HttpDown(Context context, String Url, String filePath) { 
		URL imageurl; 
		int Read; 
		try { 
			imageurl = new URL(Url); 
			HttpURLConnection conn= (HttpURLConnection)imageurl.openConnection(); 
			conn.connect(); 
			int len = conn.getContentLength(); 
			byte[] raster = new byte[len]; 
			InputStream is = conn.getInputStream(); 
			FileOutputStream fos = context.openFileOutput(filePath, 0); 
		
			for (;;) { 
				Read = is.read(raster); 
				if (Read <= 0) { 
					break; 
				} 
				fos.write(raster,0, Read); 
			}
			
			is.close(); 
			fos.close(); 
		} catch (Exception e) { 
			return false; 
		} 
		return true; 
	} 
}
